find min and max elements in array